package com.woniuxy.microcouponserver.couponInfomag.mapper;

import com.woniuxy.microcommonserver.bean.coupon_pzc.CouponInfo;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true)
@Mapper
public interface CouponInfoMapper {

    @Options(useGeneratedKeys=true, keyProperty="c.id")
    @Insert("insert into coupon_info (coupon_name,start_time,end_time,access_money," +
            "to_be_use_money,issue_number,is_use,explain_desc,image,is_deleted,store_num) " +
            "values(#{c.couponName},#{c.startTime},#{c.endTime},#{c.accessMoney}," +
            "#{c.toBeUseMoney},#{c.issueNumber},1,#{c.explainDesc},#{c.image},0,#{c.storeNum})")
    int saveCouponInfo(@Param("c") CouponInfo couponInfo);

    /**
     * 修改优惠券信息
     * @param couponInfo 要修改的信息，id代表修改对象
     * @return 影响行数
     */
    int updateCouponInfo(@Param("c") CouponInfo couponInfo);

    @Update("update coupon_info set is_deleted = 1 where id = #{id}")
    int deleteCouponInfo(@Param("id")int id);

    @Select("select id,coupon_name couponName,start_time startName,end_time endName," +
            "access_money accessMoney,to_be_use_money toBeUseMoney,issue_number issueNumber," +
            "is_use isUse,explain_desc explainDesc,image,is_deleted isDeleted,store_num storeNum " +
            "from coupon_info where id = #{id}")
    CouponInfo findById(@Param("id")int id);

    /**
     * 根据条件分页查询所有
      * @param pageRequest 分页条件
     * @param couponInfo 查询条件
     * @return 优惠券数据集合
     */
    List<CouponInfo> findAllByParams(@Param("p") PageRequest pageRequest,@Param("c") CouponInfo couponInfo);

}
